package com.mobileares.midp.demo.client.page;

import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.event.dom.client.ClickHandler;
import com.google.gwt.user.client.Timer;
import com.google.gwt.user.client.ui.*;
import com.mobileares.midp.widgets.client.button.ButtonBar;
import com.mobileares.midp.widgets.client.button.CButton;
import com.mobileares.midp.widgets.client.panel.GlassPanel;
import com.mobileares.midp.widgets.client.pop.GwtPop;
import com.mobileares.midp.widgets.client.pop.IMessageConfirm;
import com.mobileares.midp.widgets.client.pop.Message;
import com.mobileares.midp.widgets.client.pop.PopPanel;

/**
 * Created by IntelliJ IDEA.
 * User: Tom
 * Date: 2011-7-22
 * Time: 15:56:10
 * To change this template use File | Settings | File Templates.
 */
public class Window extends Composite {
    private FlowPanel panel;
    private PopPanel pp;

    public Window() {
        panel = new FlowPanel();
        initWidget(panel);
        panel.add(getBB());
        panel.add(new HTML("&nbsp;"));
        panel.add(getMessage());
    }

    public void initPop() {
        pp = new PopPanel();
//        pp.setWidth("");
        pp.setHeadText("人员信息");
        pp.addBodyWidget(new Label("MY BODY!!!"));
        pp.addFootButton(new CButton("确定"));
        pp.addFootButton(new CButton("取消"));
    }

    private Widget getBB() {
        initPop();
        ButtonBar bar = new ButtonBar();
        CButton c1 = new CButton("PopPanel");
        c1.addClickHandler(new ClickHandler() {
            public void onClick(ClickEvent event) {
                pp.show();
            }
        });

        CButton c2 = new CButton("glass");
        final GlassPanel panel = GlassPanel.getInstance();
        c2.addClickHandler(new ClickHandler() {
            public void onClick(ClickEvent event) {
                panel.show();
                Timer time = new Timer() {
                    @Override
                    public void run() {
                        panel.hidden();
                    }
                };
                time.schedule(5000);
            }
        });
        CButton c3 = new CButton("test");
        c3.addClickHandler(new ClickHandler() {
            public void onClick(ClickEvent event) {
                final PopupPanel pp = new PopupPanel();
                pp.setGlassEnabled(true);
                pp.show();
                pp.add(new Label("test"));
                Timer time = new Timer() {
                    @Override
                    public void run() {
                        pp.hide();
                    }
                };
                time.schedule(5000);
            }
        });

        bar.addButton(c1);
        bar.addButton(c2);
        bar.addButton(c3);
        return bar;
    }

    private Widget getMessage() {
        ButtonBar bb = new ButtonBar();
        CButton cb1 = new CButton("info");
        CButton cb2 = new CButton("alert");
        CButton cb3 = new CButton("error");
        CButton cb4 = new CButton("confirm");
        CButton cb5 = new CButton("complex");
        CButton cb6 = new CButton("gwtpop");
        bb.addButton(cb1);
        bb.addButton(cb2);
        bb.addButton(cb3);
        bb.addButton(cb4);
        bb.addButton(cb5);
        bb.addButton(cb6);
        cb1.addClickHandler(new ClickHandler() {
            public void onClick(ClickEvent event) {
                Message info = new Message(Message._INFO, "提示信息！");
                info.show();
            }
        });
        cb2.addClickHandler(new ClickHandler() {
            public void onClick(ClickEvent event) {
                Message info = new Message(Message._ERROR, "错误信息！");
                info.show();
            }
        });
        cb3.addClickHandler(new ClickHandler() {
            public void onClick(ClickEvent event) {
                Message info = new Message(Message._ALERT, "警告信息！");
                info.show();
            }
        });
        cb4.addClickHandler(new ClickHandler() {
            public void onClick(ClickEvent event) {
                Message info = new Message(Message._CONFIRM, "确认信息！");
                info.show();
                info.setConfirmEvent(new IMessageConfirm() {
                    public void fire(boolean confirm) {
                        Message info = new Message(Message._INFO, confirm + "");
                        info.show();

                    }
                });
            }
        });
        cb6.addClickHandler(new ClickHandler() {
            public void onClick(ClickEvent event) {
                GwtPop pop = new GwtPop();
                pop.setWidget(new Label("body!!!"));
                pop.center();
            }
        });
        return bb;
    }

}
